package com.recycle.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.recycle.system.domain.dto.ReferPriceDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.recycle.common.annotation.Log;
import com.recycle.common.core.controller.BaseController;
import com.recycle.common.core.domain.CommonResult;
import com.recycle.common.enums.BusinessType;
import com.recycle.system.domain.WasteResource;
import com.recycle.system.service.IWasteResourceService;
import com.recycle.common.utils.poi.ExcelUtil;
import com.recycle.common.core.page.TableDataInfo;

/**
 * 再生资源Controller
 *
 * @author recycle
 * @date 2023-03-11
 */
@RestController
@RequestMapping("/system/resource")
@Api(tags = "再生资源信息")
public class WasteResourceController extends BaseController
{
    @Autowired
    private IWasteResourceService wasteResourceService;

    /**
     * 查询再生资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:resource:list')")
    @GetMapping("/list")
    @ApiOperation("")
    public TableDataInfo list(WasteResource wasteResource)
    {
        startPage();
        List<WasteResource> list = wasteResourceService.selectWasteResourceList(wasteResource);
        return getDataTable(list);
    }
    /**
     * 查询再生资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:resource:list')")
    @GetMapping("/fuzzy")
    @ApiOperation("")
    public TableDataInfo fuzzyList(WasteResource wasteResource)
    {
        startPage();
        List<WasteResource> list = wasteResourceService.fuzzySelectWasteResourceList(wasteResource);

        return getDataTable(list);
    }

    /**
     * 查询参考价格列表
     */
    @PreAuthorize("@ss.hasPermi('system:resource:list')")
    @GetMapping("/refer")
    @ApiOperation("")
    public TableDataInfo refer()
    {
        startPage();
        List<ReferPriceDTO> list = wasteResourceService.selectReferPrice();
        return getDataTable(list);
    }

    /**
     * 导出再生资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:resource:export')")
    @Log(title = "再生资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("")
    public void export(HttpServletResponse response, WasteResource wasteResource)
    {
        List<WasteResource> list = wasteResourceService.selectWasteResourceList(wasteResource);
        ExcelUtil<WasteResource> util = new ExcelUtil<WasteResource>(WasteResource.class);
        util.exportExcel(response, list, "再生资源数据");
    }

    /**
     * 获取再生资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:resource:query')")
    @GetMapping(value = "/{resourceId}")
    @ApiOperation("")
    public CommonResult getInfo(@PathVariable("resourceId") Long resourceId)
    {
        return success(wasteResourceService.selectWasteResourceByResourceId(resourceId));
    }

    /**
     * 新增再生资源
     */
    @PreAuthorize("@ss.hasPermi('system:resource:add')")
    @Log(title = "再生资源", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("")
    public CommonResult add(@RequestBody WasteResource wasteResource)
    {
        return toAjax(wasteResourceService.insertWasteResource(wasteResource));
    }

    /**
     * 修改再生资源
     */
    @PreAuthorize("@ss.hasPermi('system:resource:edit')")
    @Log(title = "再生资源", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("")
    public CommonResult edit(@RequestBody WasteResource wasteResource)
    {
        return toAjax(wasteResourceService.updateWasteResource(wasteResource));
    }

    /**
     * 删除再生资源
     */
    @PreAuthorize("@ss.hasPermi('system:resource:remove')")
    @Log(title = "再生资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{resourceIds}")
    @ApiOperation("")
    public CommonResult remove(@PathVariable Long[] resourceIds)
    {
        return toAjax(wasteResourceService.deleteWasteResourceByResourceIds(resourceIds));
    }
}
